package com.jane.addressbook.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jane.addressbook.bean.Addressbook;
import com.jane.addressbook.jdbc.DBConnection;
import com.jane.addressbook.manager.AddressbookManager;


public class DisplayServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3532963715600360560L;
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req,resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Connection conn = DBConnection.getConnection();
		System.out.println(conn);
		
		AddressbookManager manager = new AddressbookManager(conn);
		List<Addressbook> list = manager.query();
		System.out.println(list);
		
		req.setAttribute("list", list);
		try {
			req.getRequestDispatcher("/list.jsp").forward(req, resp);
		} catch (Exception e) {}
		DBConnection.closeConnection(conn);
	}
}
